import { createRouter, createWebHashHistory } from 'vue-router'
import HomePage from '../views/home-page/index.vue'
import { regiserRoute } from "../global-register"

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'home',
    component: HomePage
  },
  {
    path: '/messageboard',
    name: 'messageboard',
    component: () => import(/* webpackChunkName: "messageboardpage" */ '../views/message-board-page/index.vue')
  },
  {
    path: '/weblog',
    name: 'weblog',
    component: () => import(/* webpackChunkName: "weblog" */ '../views/weblog-page/index.vue')
  },
  {
    path: '/weblog/:id',
    name: 'weblogdetail',
    component: () => import(/* webpackChunkName: "weblog" */ '../views/detail-weblog/index.vue')
  },
  {
    path: '/relax',
    name: 'relax',
    component: () => import(/* webpackChunkName: "relax" */ '../views/relax-page/index.vue')
  },
  {
    path: '/project',
    name: 'project',
    component: () => import(/* webpackChunkName: "project" */ '../views/project-page/index.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkname: "login" */ '../views/login-page/index.vue')
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'notfound',
    component: () => import(/* webpackChunkName: "notfoundpage" */ '../views/not-found-page/index.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 根据是否存在token动态注册路由
if (localStorage.getItem('token')) {
  regiserRoute(router)
}


export default router
